package top.superflow.flow.config.parse.impl

import top.superflow.core.utils.IdentifiableUtils
import top.superflow.exception.RequestUnsupportedException
import top.superflow.flow.config.dependency.DependencyManager
import top.superflow.flow.config.parse.Parser
import top.superflow.flow.config.process.provider.ProcessProviderConfig
import top.superflow.flow.runtime.processprovider.RuntimeProcessProvider
import top.superflow.flow.runtime.resource.RuntimeResource

trait ProcessProviderConfigParser extends Parser[RuntimeProcessProvider]{




  def parse(original: Any): RuntimeProcessProvider = {
    original match {
        
      case option: Some[_] => {
        parse(option.get)
      }
      case processProviderConfig: ProcessProviderConfig => {
        val runtimeProcessProvider = getProcessProvider

        IdentifiableUtils.copy(processProviderConfig, runtimeProcessProvider )

        val dependencyConfigs = processProviderConfig.getDependencies

        val dependencies = DependencyManager.getInstance.getDependency[RuntimeResource](dependencyConfigs)

        runtimeProcessProvider.setDependencies(dependencies)

        runtimeProcessProvider
      }
      case _ => {
        throw new RequestUnsupportedException("ProcessProviderConfigParser only supports ProcessProviderConfig, not support {}", original)
      }
    }
  }

  protected def getProcessProvider : RuntimeProcessProvider

}



